package com.rephilo.consumer.controller;

import com.rephilo.consumer.proxy.HelloServiceProxy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@RestController
public class BenchmarkController {

    @Autowired
    private HelloServiceProxy helloServiceProxy;

    private ExecutorService pool = Executors.newSingleThreadExecutor();

    @PostMapping("benchmark")
    public String benchmark() {
        pool.submit(() -> {
            while (true) {
                long l = System.currentTimeMillis() % 3;
                if (l == 0L) {
                    helloServiceProxy.methodA();
                } else if (l == 1) {
                    helloServiceProxy.methodB();
                } else {
                    helloServiceProxy.methodC();
                }
            }
        });

        return "提交成功";
    }


}
